//
//  discountDetailsTableViewCell.m
//  Journey
//
//  Created by dllo on 16/5/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "discountDetailsTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation discountDetailsTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createDiscount];
    }
    return self;
}

-(void)createDiscount{
    self.titleLabel = [[UILabel alloc] init];
 //   self.titleLabel.backgroundColor = [UIColor grayColor];
    self.titleLabel.numberOfLines = 2;
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.titleLabel];
    
    self.photo = [[UIImageView alloc]init];
  //  self.photo.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.photo];
    self.priceLabel = [[UILabel alloc] init];
//    self.priceLabel.backgroundColor = [UIColor yellowColor];
    self.priceLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:self.priceLabel];
    self.priceoffLabel = [[UILabel alloc] init];
//    self.priceoffLabel.backgroundColor = [UIColor yellowColor];
    self.priceoffLabel.font = [UIFont systemFontOfSize:13];
    self.priceoffLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.priceoffLabel];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.photo.frame = CGRectMake(10 * WIDTHC , 10 * WIDTHC, self.contentView.frame.size.width / 4 , self.contentView.frame.size.height - 20);
    self.titleLabel.frame = CGRectMake(self.photo.frame.size.width + 20, self.photo.frame.origin.y, self.contentView.frame.size.width - self.photo.frame.size.width - 20, self.photo.frame.size.height / 2 + 10);
    self.priceoffLabel.frame = CGRectMake(self.titleLabel.frame.origin.x, self.contentView.frame.size.height - self.titleLabel.frame.size.height + 10 , 80 * WIDTHC, 20 * WIDTHC);
    self.priceLabel.frame = CGRectMake(self.photo.frame.size.width * 3 , self.priceoffLabel.frame.origin.y - 10,80 * WIDTHC , 30 * WIDTHC);
    
}

-(void)setDismodel:(DiscountModel *)dismodel{
    
    _dismodel = dismodel;
    
    [self.photo sd_setImageWithURL:[NSURL URLWithString:_dismodel.photo] placeholderImage:[UIImage imageNamed:@"image3"]];
    
    self.titleLabel.text = _dismodel.title;
    self.priceoffLabel.text = _dismodel.priceoff;
    
    NSRegularExpression *regular = [NSRegularExpression regularExpressionWithPattern:@"[a-zA-Z.<,>,/]" options:0 error:NULL];
    
    NSString *string = _dismodel.price;
    NSString *price= [regular stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@""];
    self.priceLabel.text = price;
}

@end
